package aad.storyboard.controller;

import aad.storyboard.R;
import aad.storyboard.model.*;
import aad.storyboard.view.BackButton;
import aad.storyboard.view.GraphicView;
import aad.storyboard.view.NextButton;
import aad.storyboard.view.PauseButton;
import aad.storyboard.view.StaticScriptView;
import aad.storyboard.view.StoryBar;
import aad.storyboard.view.WikiBackButton;
import aad.storyboard.view.WikiView;
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageButton;
import android.widget.SeekBar;
import android.widget.ViewFlipper;

public class GUIComposer extends Thread{
	
	private static GUIComposer instance = new GUIComposer();
	private int fps = 25; 
	private View mainLayout;
	private GraphicView graphicalView;
	private StaticScriptView  scriptView;
	private WikiView  wikiView;	
	private ViewFlipper flipper;
	private Activity activity;
	private PauseButton pause;
	private BackButton back;
	private NextButton next;
	
	private NavigationController nc;
	
	
	public static GUIComposer getInstance(){
		return instance;
	}
	
	 
	private void GUIController(){
	}
	
	
	/**
	 * Facade in which all the views are set, such that the user of the API must not perform these actions manually.
	 */
	public void setupGUI(Story s, Activity a, int mL){

	    this.mainLayout = a.findViewById(mL);
		Log.e("hallo",this.mainLayout+"");
		this.activity=a;
	    this.flipper = (ViewFlipper) a.findViewById(R.id.flipper);  	   
		StoryBar volControl = (StoryBar) a.findViewById(R.id.volbar);	

		nc=NavigationController.getInstance(volControl, this.activity); 
	   
	  this.graphicalView= (GraphicView)a.findViewById(R.id.graphicView);	   
	  this.scriptView=(StaticScriptView)a.findViewById(R.id.scriptView);	 
	  this.wikiView=(WikiView)activity.findViewById(R.id.wikiView);
	  	  
	  //WebSettings ws = scriptView.getSettings();
	 // ws.setJavaScriptEnabled(true);  
	  //JavaScriptInterface intf=new JavaScriptInterface(activity, wikiView, flipper);
	  //scriptView.setJavaScriptInterface(intf);	   
	  
	   graphicalView.setOnTouchListener(new ViewTouchListener(s));	   
	    
	   NavigationClickListener navList= NavigationClickListener.getInstance();
	    pause=(PauseButton)a.findViewById(R.id.pause);
	    pause.setOnClickListener(navList);
	    back=(BackButton)a.findViewById(R.id.backward);	    
	    back.setOnClickListener(navList);
	    next=(NextButton)a.findViewById(R.id.forward);	    
	    next.setOnClickListener(navList);
	    WikiBackButton backtomain=(WikiBackButton)a.findViewById(R.id.back);
	    backtomain.setOnClickListener(navList);
	    
	    BackNavigator backnav=new BackNavigator(a); 
	    PauseNavigator pausenav=new PauseNavigator(a);
	    NextNavigator nextnav=new NextNavigator(a);
	    BackToMainViewNavigator backToMainnav=new BackToMainViewNavigator (a);
	     
	    navList.register(back.getId(), backnav);
	    navList.register(pause.getId(), pausenav);
	    navList.register(next.getId(), nextnav);
	    navList.register(backtomain.getId(), backToMainnav);
	    
	    
	     //Drag and Drop
	    DragDropManager.getInstance().init(graphicalView);	    
	 
	}
	
	//getters and setters
	public View getMainView(){
		return this.mainLayout;
	}
	
	public View getGraphicalView(){
		return this.graphicalView;
	}

	public int getFps(){
		return this.fps;
	}


	public StaticScriptView getScriptView() {
		return this.scriptView;
	}
	
	public void setMainView(View v){
		this.mainLayout = v;
	}


	public ViewFlipper getFlipper() {		
		return flipper;
	}


	public WebView getWikiView() {		
		return wikiView;
	}


	public PauseButton getPauseButton() {
		// TODO Auto-generated method stub
		return pause;
	}


	public BackButton getBackButton() {
		// TODO Auto-generated method stub
		return back;
	}


	public NextButton getNextButton() {
		// TODO Auto-generated method stub
		return next;
	}
			
}
